MODULE pfmm_periodic_images

   USE fmm_global_consts
   USE fmm_global_types
!   USE fmm_W_contractors,  ONLY: fmm_init_W_contractors,           &
!                                 fmm_free_W_contractors

!   USE fmm_box_utils,      ONLY: fmm_deepest_level
!   USE fmm_box_builder,    ONLY: fmm_get_box_qlm_at_level,         &
!                                 fmm_get_box_paras_at_level
!   USE fmm_W_pair_builder, ONLY: fmm_get_raw_Vff_from_boxed_Vff

   IMPLICIT NONE
   PRIVATE
   ! Public procedures
   PUBLIC :: pfmm_get_periodic_image

CONTAINS

!-------------------------------------------------------------------------------

   SUBROUTINE pfmm_get_periodic_image(i,j,k,shift,cntr)

      IMPLICIT NONE
      INTEGER(INTK), INTENT(IN)  :: i,j,k
      REAL(REALK),   INTENT(IN)  :: shift(3)
      REAL(REALK),   INTENT(OUT) :: cntr(3)

      cntr(1) = shift(1)*i
      cntr(2) = shift(2)*j
      cntr(3) = shift(3)*k

   END SUBROUTINE pfmm_get_periodic_image

!-------------------------------------------------------------------------------

END MODULE pfmm_periodic_images

!
!   SUBROUTINE pfmm_get_FQ_Vff(scheme,LHS_paras,RHS_mms,Vff)
!
!      IMPLICIT NONE
!      TYPE(raw_mm_paras), TARGET, INTENT(IN)    :: LHS_paras(:)
!      TYPE(raw_mm_data),          INTENT(IN)    :: RHS_mms
!      TYPE(fmm_scheme),           INTENT(IN)    :: scheme
!      REAL(REALK),        TARGET, INTENT(INOUT) :: Vff(:,:)
!
!      INTEGER(INTK), PARAMETER :: pair_type = LHS_raw_RHS_raw
!      TYPE(gen_mm_paras) :: LHS, RHS
!      TYPE(fmm_range) :: nsupercell
!      REAL(REALK) :: T0, T1, xshift
!      INTEGER(INTK) :: i
!
!      CALL CPU_TIME(T0)
!      NULLIFY(LHS%raw_paras,LHS%box_paras)
!      NULLIFY(RHS%raw_paras,RHS%box_paras)
!
!      LHS%raw_paras => LHS_paras(:)
!      RHS%raw_paras => RHS_mms%paras(:)
!
!      ! select the T-contractor to be stored/called via C code;
!      CALL fmm_select_T_con(scheme)
!      ! set T_contractor pointers   
!      CALL fmm_set_T_con_ptrs(Vff,RHS_mms%qlm_T)
!      CALL fmm_init_T_contractors(scheme)
!
!      ! generate full multipole potential 
!      CALL fmm_init_T_pair_builder(scheme,pair_type)
!
!      ! iterate with 1D periodic repetition over supercells
!      nsupercell%lo = -2
!      nsupercell%hi = 2
!      xshift = 5.0d0
!      CALL pfmm_get_periodic_image(xshift*nsupercell%lo,RHS%raw_paras)
!      CALL fmm_gen_nonlocal_T_pairs(LHS,RHS,pair_type)
!      DO i = nsupercell%lo+1, nsupercell%hi 
!         ! skip NN supercells
!         IF (ABS(i)==1 .OR. i==0) CYCLE 
!         CALL pfmm_get_periodic_image(xshift,RHS%raw_paras)
!         CALL fmm_gen_nonlocal_T_pairs(LHS,RHS,pair_type)
!      END DO
!      CALL fmm_close_T_pair_builder(scheme)
!      CALL fmm_free_T_contractors
!
!      CALL CPU_TIME(T1)
!      CALL fmm_TIMTXT('>>> TIME USED in pfmm_get_FQ_Vff', T1-T0, IO1)
!
!   END SUBROUTINE pfmm_get_FQ_Vff
!
!-------------------------------------------------------------------------------

